package id.net.iconpln.bb.client.tools;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

public class FusionChartWidget	extends Composite {



		  public final static int TYPE_CYLINDER = 1;		  
		  public final static int TYPE_DETAIL = 2;
		  private static int seqId = 1;
		  private HTML holder = null;
		  private String divId = null;;
		  private int chartType = TYPE_CYLINDER;
//		  private int chartType = null;
		  private String width = "0";
		  private String idChart = null;
		  private String height = "0";
		  private String swf = null;
		  private String dataUrl = null;
		  private String dataXml = null;
		  private boolean transparent = true;
		  private boolean debug = false;
		  private String XMLLoadingText;
		  private String ParsingDataText;
		  private String PBarLoadingText;
		  private String RenderingChartText;
		  public FusionChartWidget( String swf, int chartType, String width, String height) {

		    this.chartType = chartType;
		    this.width = width;
		    this.height = height;
		    this.swf = swf;
		    this.idChart = idChart;
//		    if (idDiv == null){		    	
		    	divId = "chart" + (seqId++);
//		    }else{
//		    	divId = idDiv;
//		  	}
		    holder = new HTML("<div align =\"center\" id=\""+divId+"\"></div>");		    
		    initWidget(holder);
		  }
		  
		  public void setDataUrl( String dataUrl ) {
		    this.dataUrl = dataUrl;
		  }
		  public void setIdChart( String idChart ) {
			    this.idChart = idChart;
		  }
		  public FusionCharts getIdChart(String c){
//			  FusionCharts ch = new FusionCharts(); 
//			  FusionCharts.getIdChart(c);
			  return FusionCharts.getIdChart(c);
		  }
		  public void setDataXml( String dataXml ) {
			    this.dataXml = dataXml;
		  }
		  public void setXMLLoadingText( String xMLLoadingText ) {
			    this.XMLLoadingText = xMLLoadingText;
		  }
		  public void setParsingDataText( String parsingDataText ) {
				this.ParsingDataText = parsingDataText;
		  }
		  public void setPBarLoadingText( String pBarLoadingText ) {
			    this.PBarLoadingText = pBarLoadingText;
		  }
		  public void setTransparent( boolean transparent ) {
			    this.transparent = transparent;
		  }
		  public void setdebugMode( boolean debug ) {
			    this.debug = debug;
		  }		  
		  public void setRenderingChartText(String renderingChartText){
			  this.RenderingChartText = renderingChartText;
		  }
		  protected void initWidget( Widget widget ) {
		    super.initWidget( widget );
		  }
		  protected void onAttach( ) {
		    FusionCharts chart = null;
		    switch ( chartType ) {
		      case TYPE_CYLINDER:
//		        chart = FusionCharts.getChart(swf ,Integer.toString( width ), Integer.toString( height ) );
			        chart = FusionCharts.getChart(swf ,"idchatnormal","0", width , height );
		      break;
		      case TYPE_DETAIL:
//			        chart = FusionCharts.getChart(swf ,Integer.toString( width ), Integer.toString( height ) );
		    	  String d;
		    	  if (debug == true){
		    		  d ="1";
		    	  }else{
		    		  d ="0";
		    	  }
			        chart = FusionCharts.getChart(swf , idChart,d,width , height );
			  break;
		    }
		    
//		    chart.setDataUrl( dataUrl );
		    chart.setRenderingChartText(RenderingChartText);
		    chart.setParsingDataText(ParsingDataText);
		    chart.setPBarLoadingText(PBarLoadingText);
		    chart.setXMLLoadingText(XMLLoadingText);
		    chart.setTransparent(transparent);
		    chart.setdebugMode(debug);
		    chart.setDataXml(dataXml);
		    chart.render( divId );

		  }

}
